import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export interface Cook {
  id: number,
  name: string;
  category?: string;
  content: string;
}

// 菜篮
export const useBasketStore = defineStore('basket', () => {
  const results = ref<Array<Cook>>([])

  function add(obj: Cook) {
    results.value.push(obj)
  }

  function size(): string {
    return results.value.length == 0 ? "" : results.value.length + ""
  }

  function list(): Array<Cook> {
    return results.value;
  }

  function remove(idx: number): void {
    for (let i = idx; i < results.value.length-1; i++) {
      results.value[i] = results.value[i+1]
    }
    results.value.length = results.value.length-1
  }

  return {
    size,
    add,
    list,
    remove
  }

})